package com.zxj.camerademo.camera2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.TextureView;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.zxj.camerademo.R;

public class Camera2Activity extends AppCompatActivity implements View.OnClickListener {

    private Camera2Helper mCamera2Helper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera2);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        TextureView textureView = findViewById(R.id.textureView);
        mCamera2Helper = new Camera2Helper(this, textureView);

        ImageButton btnTakePic = findViewById(R.id.btnTakePic);
        ImageView ivExchange = findViewById(R.id.ivExchange);

        btnTakePic.setOnClickListener(this);
        ivExchange.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btnTakePic:
                mCamera2Helper.takePic();
                break;
            case R.id.ivExchange:
                mCamera2Helper.exchangeCamera();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mCamera2Helper.releaseCamera();
        mCamera2Helper.releaseThread();
    }
}
